package com.gx.util.base;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.net.InetAddress;

/**
 * @author gaoxing
 * @create 2018-06-19 下午3:55
 */
@Slf4j
public class BaseMachineUtils {
    public static String getHostName() {
        String hostName = null;

        try {
            InetAddress address = InetAddress.getLocalHost();
            hostName = address.getHostName();
        } catch (Throwable var3) {
            ;
        }

        if (StringUtils.isNotBlank(hostName) && !"localhost".equalsIgnoreCase(hostName)) {
            return hostName;
        } else {
            try {
                hostName = BaseProcessUtils.run(new String[]{"hostname"});
            } catch (Exception var2) {
                ;
            }

            return StringUtils.isNotBlank(hostName) && !"localhost".equalsIgnoreCase(hostName) ? hostName : null;
        }
    }

//    public static void main(String[] args) {
//        System.out.println(getHostName());
//    }

}
